<?php

namespace App\Http\Resources\Api;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'phone' => $this->phone,
            'nickname' => $this->nickname,
            'realname' => $this->realname,
            'avatar_url' => $this->avatar_url,
            'gender' => $this->gender,
            'is_member' => $this->is_member,
            'member_expired_date' => $this->member_expired_time ? Carbon::parse($this->member_expired_time)->toDateString() : '',
            'member_expired_time' => $this->member_expired_time,
            'member_remain_times' => $this->member_remain_times,
            'created_at' => (string)$this->created_at,
            'updated_at' => (string)$this->updated_at
        ];
    }
}
